package com.boang.controller;

import com.auth0.jwt.exceptions.JWTVerificationException;
import com.boang.resp.Result;
import com.boang.utils.JwtTokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;

/*
  @author: 13813
  @date: 2024/9/11 9:54
*/
@RestController
public class TokenController {

    @Autowired
    JwtTokenUtils jwtTokenUtils;

    @RequestMapping("/verification/{token}")
    public Result<String> verificationToken(@PathVariable("token") String token) throws UnsupportedEncodingException {
        try {
            jwtTokenUtils.extractClaim(token);
        } catch (JWTVerificationException e) {
            return Result.failed("验证失败");
        }
        return Result.ok("验证成功");
    }
}
